/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package data;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.*;
/**
 *
 * @author NS
 */
public class List_Role {
    private Connection conn;
    public List_Role(Connection conn){
        this.conn = conn;
    }
    public ArrayList<String> roleList(String username){
        Statement stmt;
        ArrayList<String> lst = null;
        try{
            stmt = conn.createStatement();
            
            String query = "SELECT GRANTED_ROLE FROM SYS.DBA_ROLE_PRIVS WHERE GRANTEE = '" + 
            				username + "' AND ADMIN_OPTION = 'YES'";
            if(username.equals("ADMIN")){
            	query = "SELECT ROLE FROM DBA_ROLES";
            }
            System.out.println(query);
            ResultSet rs = stmt.executeQuery(query);
            
            lst = new ArrayList<String>();
            while(rs.next()){
                lst.add(rs.getString(1));
            }
        }catch(Exception e){
            System.out.println(e);
        }
        return lst;
    }
}
